<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8"> </meta>

    <!-- BEGIN GLOBAL MANDATORY STYLES -->
    <link href="/static/assets/plugins/font-awesome/css/font-awesome.min.css"rel="stylesheet" type="text/css"/>
    <link href="/static/assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="/static/assets/plugins/uniform/css/uniform.default.css"  rel="stylesheet" type="text/css"/>
    <!-- END GLOBAL MANDATORY STYLES -->
    <!-- BEGIN PAGE LEVEL STYLES -->
    <link rel="stylesheet" type="text/css" href="/static/assets/plugins/select2/select2.css"/>
    <link rel="stylesheet" type="text/css" href="/static/assets/plugins/select2/select2-metronic.css" />
    <!-- END PAGE LEVEL STYLES -->
    <!-- BEGIN THEME STYLES -->
    <link href="/static/assets/css/style-metronic.css"rel="stylesheet" type="text/css"/>
    <link href="/static/assets/css/style.css"  rel="stylesheet" type="text/css"/>
    <link href="/static/assets/css/style-responsive.css" rel="stylesheet" type="text/css"/>
    <link href="/static/assets/css/plugins.css"rel="stylesheet" type="text/css"/>

    <script src="/static/assets/plugins/jquery-1.10.2.min.js"type="text/javascript"></script>
    <!-- IMPORTANT! Load jquery-ui-1.10.3.custom.min.js before bootstrap.min.js to fix bootstrap tooltip conflict with jquery ui tooltip -->
    <script src="/static/assets/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <script src="/static/assets/plugins/bootbox/bootbox.min.js"  type="text/javascript"></script>

    <script src="/static/assets/scripts/core/datatable.js"></script>

    <script type="text/javascript">

        $("#saveProject").click(function(){
            debugger;
            save();
        });


        function save(){

            var dataArray = [];


            $("[name='form']").each(function(){


                var $this = $(this);
                var data = {};
                $this.find('[isForm="true"]').each(function(){
                    var $input = $(this);
                    var name = $input.attr('name');

                    if(name == 'isCondition'){
                        if(this.checked){
                            data[name] = '1';
                        }else{
                            data[name] = '-1';
                        }

                    } else 
                        if(name == 'isUpdate' || name == 'isInsert'){
                            if(this.checked){
                                data[name] = '1';
                            }else{
                                data[name] = '-1';
                            }

                        } else {
                        data[$input.attr('name')] = $input.val();
                    }

                });
                dataArray.push(data);
            });
            var tableName = $("#tableName").attr('tableName');
            console.log(dataArray);
            $.ajax({
                url:"/entity/saveEntity?tableName=" + tableName,
                type:"POST",
                data: JSON.stringify(dataArray),
                contentType: 'application/json;charset=utf-8',
                success:function ( backData ) {
                    if( backData && backData.code ){
                        bootbox.alert("保存项目数据成功!");
                    }
                }
            });
        }

    </script>
    <title>表列信息</title>
</head>
<body id="tableName" th:attr="tableName=${tableName}">

<div class="portlet-body form">
    <!-- BEGIN FORM-->
    <form action="#" class="form-horizontal" >
        <table class ="table table-striped">
            <tr>
                <th>列名</th>
                <th>属性名</th>
                <th>数据类型</th>
                <th>作为查询条件</th>
                <th>WHERE条件</th>
                <th>更新</th>
                <th>插入</th>
                <th>描述</th>
                <th>列键</th>
            </tr>
            <tr name="form" th:each="column : ${list}">
                <td>
                    <input isForm="true" name="columnName" class="form-control" th:attr="value=${column.columnName}">
                </td>
                <td >
                    <input isForm="true" name="propertyName"  class="form-control"  th:attr="value=${column.propertyName}" >
                </td>

                <td>
                    <select isForm="true" name="javaType" placeholder="选择合适的数据类型" class="chosen-select form-control" tabindex="2">
                        <option value="java.lang.String"  th:selected="${column.javaType == 'java.lang.String'}">String</option>
                        <option value="java.lang.Integer"  th:selected="${column.javaType == 'java.lang.Integer'}">Integer</option>
                        <option value="java.lang.Double"  th:selected="${column.javaType == 'java.lang.Double'}">Double</option>
                        <option value="java.lang.Long"  th:selected="${column.javaType == 'java.lang.Long'}">Long</option>
                        <option value="boolean"  th:selected="${column.javaType == 'boolean'}">boolean</option>
                        <option value="java.util.Date"  th:selected="${column.javaType == 'java.util.Date'}">Date</option>
                        <option value=""></option>
                    </select>
                </td>
                <td>
                    <div class="switch switch-inline">
                        <input isForm="true" name="isCondition" type="checkbox" checked > </input>

                    </div>
                </td>
                <!-- <td th:text="${column.nullAble}"></td>-->
                <td>
                    <div class="switch switch-inline">
                        <select isForm="true" name="conditionType" placeholder="查询类型" class="chosen-select form-control" tabindex="2">
                            <option value=""></option>
                            <option value="like_"  th:selected="${column.javaType == 'java.lang.String'}">前匹配</option>
                            <option value="like-"  th:selected="${column.javaType == 'java.lang.Integer'}">后匹配</option>
                            <option value="like="  th:selected="${column.javaType == 'java.lang.Double'}">前后匹配</option>
                            <option value="eq"  th:selected="${column.javaType == 'java.lang.Long'}">等于</option>
                            <option value="eq"  th:selected="${column.javaType == 'boolean'}">等于</option>
                            <option value="gt"  th:selected="${column.javaType == 'java.util.Date'}">大于</option>
                            <option value="gt&eq"  th:selected="${column.javaType == 'java.util.Date'}">大于等于</option>
                            <option value="lt"  th:selected="${column.javaType == 'java.util.Date'}">小于</option>
                            <option value="lt&eq"  th:selected="${column.javaType == 'java.util.Date'}">大于等于</option>
                            <option value="between"  th:selected="${column.javaType == 'java.util.Date'}">范围查</option>

                        </select>
                    </div>
                </td>
                <td>
                    <div class="switch switch-inline">
                        <input isForm="true" name="isUpdate" type="checkbox" value="checked"> </input>
                        <label>可空</label>
                    </div>
                </td>
                <td>
                    <div class="switch switch-inline">
                        <input  isForm="true"  name="isInsert" type="checkbox"  value="checked"> </input>
                        <label>可空</label>
                    </div>
                </td>
                <td >  <input  isForm="true"  name="columnComment"   class="form-control" th:attr="value=${column.columnComment}"></td>
                <td  th:text="${column.columnKey}"> </td>
            </tr>
        </table>

            <div class="form-actions fluid">
                <div class="col-md-offset-3 col-md-9">
                    <button id="saveProject" type="button" onclick="save()" class="btn blue">保存</button>
                    <button type="button" class="btn default">取消</button>
                </div>
            </div>
    </form>
    <!-- END FORM-->
</div>

</body>

</html>